#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        /*int k = 1; 
        vector<int>::iterator itor;
        int flag  = nums[0];
        for (itor = ++(nums.begin())
            ;itor != nums.end();
            )
        {
            if ((flag ^ (*itor)) != 0)
            {
                flag = *itor;
                ++k;
                itor++;
            }
            else
            {
                itor = nums.erase(itor);
            }
        }*/
        if (nums.size() == 0)
        {
            return 0;
        }
        int fast = 1, slow = 1;
        while (fast < nums.size())
        {
            if (nums[fast] != nums[fast - 1])
            {
                nums[slow] = nums[fast];
                ++slow;
            }
            ++fast;
        }
        return slow;
    }
};

int main()
{
    Solution s;
    vector<int> nums;
    //nums.push_back(0);
    //nums.push_back(0);
    nums.push_back(1);
    nums.push_back(1);
    nums.push_back(2);

    cout << s.removeDuplicates(nums) << endl;
    for (const auto e : nums)
    {
        cout << e << ' ';
    }



    return 0;
}